﻿Imports System.Windows.Forms

Public Class Principal

#Region "Variables privadas y propiedades de la clase"

    Private _idUsuario As Integer
    Private _nombreUsuario As String
    Private _aereo As Boolean
    Private _maritimo As Boolean

    Public Property IdUsuario() As Integer
        Get
            Return Me._idUsuario
        End Get
        Set(ByVal value As Integer)
            Me._idUsuario = value
        End Set
    End Property
    Public Property NombreUsuario() As String
        Get
            Return Me._nombreUsuario
        End Get
        Set(ByVal value As String)
            Me._nombreUsuario = value
        End Set
    End Property
    Public Property Aereo() As Boolean
        Get
            Return Me._aereo
        End Get
        Set(ByVal value As Boolean)
            Me._aereo = value
        End Set
    End Property
    Public Property Maritimo() As Boolean
        Get
            Return Me._maritimo
        End Get
        Set(ByVal value As Boolean)
            Me._maritimo = value
        End Set
    End Property
#End Region

    Private Sub SalirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalirToolStripMenuItem.Click
        Me.Close()
    End Sub


    Private Sub Principal_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Icon = My.Resources.ark
        Me.lblNombreUsuario.Text = "Usuario: " & Me.NombreUsuario
        'Oculta menus sobre los que el usuario no tiene permisos
        Me.Permisos()
    End Sub

    ''' <summary>
    ''' Oculta los menus sobre los que el usuario no tiene permisos
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Permisos()
        Try
            Cursor = Cursors.WaitCursor
            'Trae los menus sobre los que tiene permisos
            Dim oAut As New CAutenticacion
            Dim ds As New DataSet
            Dim arrMenus As New ArrayList()
            ds = oAut.GetPermisos(Me.IdUsuario)
            If (ds.Tables(0).Rows.Count > 0) Then
                'Construye arreglo con los menus que le llegan            
                For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
                    arrMenus.Add(ds.Tables(0).Rows(i)("NOMBRE"))
                Next
            End If

            'Recorre los menus existentes y los que no están en el arreglo los oculta
            For Each opcion As ToolStripMenuItem In Me.MenuStrip.Items
                If (opcion.Tag <> "") Then
                    If Not (arrMenus.Contains(opcion.Tag)) Then
                        opcion.Visible = False
                    Else
                        'Recorre los submenús
                        For i As Integer = 0 To opcion.DropDownItems.Count - 1
                            'Si el submenu no tiene tag se le muestra a todos los usuarios
                            If (opcion.DropDownItems(i).Tag <> "") Then
                                'Si el tag no esta en el dataset es porque no tiene permisos 
                                If Not (arrMenus.Contains(opcion.DropDownItems(i).Tag)) Then
                                    opcion.DropDownItems(i).Visible = False
                                End If
                            End If
                        Next
                    End If                
                End If
            Next

            'Se evalúa qué permisos llegan de aéreo y marítimo
            Me.Aereo = False
            Me.Maritimo = False
            If (ds.Tables(1).Rows.Count > 0) Then
                For i As Integer = 0 To ds.Tables(1).Rows.Count - 1
                    If (ds.Tables(1).Rows(i)("AEREO")) Then
                        Me.Aereo = True
                    End If
                    If (ds.Tables(1).Rows(i)("MARITIMO")) Then
                        Me.Maritimo = True
                    End If
                Next
            End If

            Cursor = Cursors.Default
        Catch ex As Exception
            Cursor = Cursors.Default
            MessageBox.Show("No se pudieron consultar los permisos del usuario: " & ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try

    End Sub

    Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
        My.Forms.CambiarClave.MdiParent = Me
        My.Forms.CambiarClave.Show()
    End Sub

    Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
        My.Forms.Perfiles.MdiParent = Me
        My.Forms.Perfiles.Show()
    End Sub

    Private Sub UsuariosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UsuariosToolStripMenuItem.Click
        My.Forms.Usuarios.MdiParent = Me
        My.Forms.Usuarios.Show()
    End Sub

    Private Sub PermisosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PermisosToolStripMenuItem.Click
        My.Forms.Permisos.MdiParent = Me
        My.Forms.Permisos.Show()
    End Sub

    Private Sub PaísesYCiudadesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PaísesYCiudadesToolStripMenuItem.Click
        My.Forms.Ciudades.MdiParent = Me
        My.Forms.Ciudades.Show()
    End Sub

    Private Sub MonedasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MonedasToolStripMenuItem.Click
        My.Forms.Monedas.MdiParent = Me
        My.Forms.Monedas.Show()
    End Sub

    Private Sub ClientesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClientesToolStripMenuItem.Click
        My.Forms.Clientes.MdiParent = Me
        My.Forms.Clientes.Show()
    End Sub


    Private Sub ConceptosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConceptosToolStripMenuItem.Click
        My.Forms.Conceptos.MdiParent = Me
        My.Forms.Conceptos.Show()
    End Sub

    Private Sub TRMToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TRMToolStripMenuItem.Click
        My.Forms.Trm.MdiParent = Me
        My.Forms.Trm.Show()
    End Sub

    Private Sub AgentesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AgentesToolStripMenuItem.Click
        My.Forms.Agentes.MdiParent = Me
        My.Forms.Agentes.Show()
    End Sub

    Private Sub ReportesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportesToolStripMenuItem.Click
        My.Forms.Reportes.MdiParent = Me
        My.Forms.Reportes.Show()
    End Sub

    'Maritimos exportacion
    Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
        My.Forms.Maritimos.MdiParent = Me
        My.Forms.Maritimos.Show()
    End Sub

    'Aereos Importacion
    Private Sub ConsolidadosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConsolidadosToolStripMenuItem.Click
        My.Forms.Consolidados.MdiParent = Me        
        My.Forms.Consolidados.Show()
    End Sub

    'Aereos Exportacion
    Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem4.Click
        My.Forms.AereoExportacion.MdiParent = Me
        My.Forms.AereoExportacion.Show()
    End Sub

    'Facturacion terceros (varios aéreo)
    Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click
        My.Forms.Terceros.MdiParent = Me
        My.Forms.Terceros.Show()
    End Sub

    'Facturacion terceros (varios marítimo)
    Private Sub ToolStripMenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem6.Click
        My.Forms.VariosMaritimo.MdiParent = Me
        My.Forms.VariosMaritimo.Show()
    End Sub

    Private Sub AeropuertosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AeropuertosToolStripMenuItem.Click
        My.Forms.Aeropuertos.MdiParent = Me
        My.Forms.Aeropuertos.Show()
    End Sub

    Private Sub GuíasToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GuíasToolStripMenuItem1.Click
        My.Forms.Guias.MdiParent = Me
        My.Forms.Guias.Show()
    End Sub

    Private Sub ReporteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReporteToolStripMenuItem.Click
        My.Forms.ReporteGuias.MdiParent = Me
        My.Forms.ReporteGuias.Show()
    End Sub

    Private Sub AerolíneasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AerolíneasToolStripMenuItem.Click
        My.Forms.Aerolineas.MdiParent = Me
        My.Forms.Aerolineas.Show()
    End Sub
End Class
